import axios from '~/plugins/axios';
import { basicConfig } from '~/assets/js/config'

/**
 * FB授权地址
 *
 * @param commit
 * @param state
 * @param preload
 */
export const bindFB = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/user/authUrl.do', {
        params: preload || {}
    })
    .catch(function (error) {
      
    });
};


/**
 * FB解绑
 *
 * @param commit
 * @param state
 * @param preload
 */
export const unbindFB = function ({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/user/unbindfb.do', preload || {})
};

/**
 * FB广告账号列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const FBAccountList = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/user/adaccounts.do', {
        params: preload || {}
    })
    .catch(function (error) {
      
    });
};

/**
 * 设置当前FB广告账号
 *
 * @param commit
 * @param state
 * @param preload
 */
export const setFBAccount = function ({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/user/currentaccount.do', preload || {})
    .catch(function (error) {

    });
};


/**
 * 保存FB token
 *
 * @param commit
 * @param state
 * @param preload
 */
export const saveFBToken = function ({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/user/saveFBToken.do', preload || {})
        .catch(function (error) {

        });
};

/**
 * 获取绑定信息列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getAllPlatformInfo = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/user/bindingList.do', {
        params: preload || {}
    })
        .catch(function (error) {

        });
};

/**
 * 获取单个平台绑定信息
 *
 * @param commit
 * @param state
 * @param preload
 */
export const bindingInfo = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/user/bindingInfo.do', {
        params: preload || {}
    })
        .catch(function (error) {

        });
};


/**
 * 谷歌登录授权接口
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getGoogleCode = function ({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/googleuser/googleAuthUrl', preload || {})
        .catch(function (error) {

        });
};


/**
 * 谷歌刷新令牌接口
 *
 * @param commit
 * @param state
 * @param preload
 */
export const refreshGoogle = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/googleuser/refreshGoogleAccessToken', {
        params: preload || {}
    })
        .catch(function (error) {

        });
};


/**
 * 谷歌获取adwords账号列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getGoogleAdwordsAccount = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/googleuser/getGoogleAdwordsAccount', {
        params: preload || {}
    })
        .catch(function (error) {

        });
};

/**
 * 设置谷歌当前ads
 *
 * @param commit
 * @param state
 * @param preload
 */
export const settingGoogleAds = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/googleuser/setGoogleCurrentAdwordsAccount', {
        params: preload || {}
    })
        .catch((error) => {

        });
};

/**
 * 绑定谷歌账号
 *
 * @param commit
 * @param state
 * @param preload
 */
export const bindGoogle = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/googleuser/getAdwordsTokenByCode', {
        params: preload || {}
    })
};

/**
 * 直接根据code获取账户列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getAdwordsAccountsByCode = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/googleuser/getAdwordsAccountsByCode', {
        params: preload || {}
    })
};

/**
 * 解绑谷歌账号
 *
 * @param commit
 * @param state
 * @param preload
 */
export const unBindGoogle = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/googleuser/unbindGoogle', {
        params: preload || {}
    })
        .catch(function (error) {

        });
};

/**
 * 获取当前谷歌广告账号信息
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getGoogleDetailInfo = function ({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/googleuser/getCurrentAdwordsAccountInfo', preload || {})
        .catch((error) => {

        });
};


/**
 * 删除google token
 *
 * @param commit
 * @param state
 * @param preload
 */
export const deleteGoogleDetailInfo = function ({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/googleuser/delete', preload || {})
        .catch((error) => {

        });
};



/**
 * 用户登录
 *
 * @param commit
 * @param state
 * @param preload
 */
export const login = function ({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/user/login', {
        params: preload || {}
    })
        .catch(function (error) {

        });
};


